##########################################################
# John Henderson and Alex Theodoridis
# Replication Data for: "Seeing Spots", 
#  Forthcoming in Political Behavior, August 20, 2017
# 
##########################################################
#
#  buildDataPres.R
#  -- preliminary file that produces the cces_data object for the
#     2012 President election data
#
##########################################################
      
# illustrates which variables are available in the dataset

run.data=F
if(run.data==T){    
  
rm(list=ls())
library(foreign)
library(stringr)

path='~/Dropbox/AGT/CCES12_AGT_UNMATCHED/'
cces_data=read.spss(paste(path,'CCES12_AGT_UNMATCHED_working.sav',sep=''))


covs=c(
# treatment/outcome variables      
"video_time","video_time2","videos_treat","videoagain","AGT309","AGT310","AGT315_3","AGT308","AGT313",                                                                                       
# demographic/political interest 
"CC309a","newsint","pid3lean","educ","ideo5","gender","birthyr","race","employ","marstat","ownhome",
"milstat_5","union","unionhh","faminc","phone","internethome","comptype","votereg","CC316","CC317",
"CC354","CC354b","CC354c","inputstate","pew_bornagain","pew_religimp","pew_churatd","pew_prayer",
"CC302","CC305","CC306","CC308a","CC309a","CC309b","CC309c","CC309d",
# summarized issue attitude score
"CC320","CC321","CC322_1","CC324","CC325","CC326","CC327","CC328","CC329",
"CC332A","CC332B","CC332C","CC332D","CC332E","CC332F","CC332G","CC332H","CC332I","CC332J","pid7")

indx=array(NA,length(covs))
for(j in 1:length(indx)){
	indx[j]=which(names(cces_data)==covs[j])
} 

cces_data=as.data.frame(cces_data)[,indx]
tr=cces_data$videos_treat
tr_time=array(NA,length(tr))
tr_time[which(tr=='Positive Obama 1')]=3.1 # M PO1.m4v
tr_time[which(tr=='Positive Obama 2')]=4.1 # M PO2.m4v
tr_time[which(tr=='Positive Obama 3')]=3.0 # M PO3.m4v
tr_time[which(tr=='Negative Obama 1')]=2.2 # M NO1.m4v
tr_time[which(tr=='Negative Obama 2')]=3.1 # M NO2.m4v
tr_time[which(tr=='Negative Obama 3')]=1.8 # M NO3.m4v
tr_time[which(tr=='Positive Romney 1')]=3.0 # M PR1.m4v
tr_time[which(tr=='Positive Romney 2')]=4.2 # M PR2.m4v
tr_time[which(tr=='Positive Romney 3')]=4.6 # M PR3.m4v
tr_time[which(tr=='Negative Romney 1')]=2.4 # M NR1.m4v
tr_time[which(tr=='Negative Romney 2')]=2.3 # M NR2.m4v
tr_time[which(tr=='Negative Romney 3')]=1.5 # M NR3.m4
cces_data$tr_time=tr_time

save(cces_data,file='~/Dropbox/Seeing_Spots/replication/cces_data_pres.Rdata') 
                    
}
#END buildDataPres.R